Weave Manual
Making Weave Scripts
intro
the general form a Weave script is a collection of definitions
followed by a return statement. The value returned must be a
rope. Ropes are defined recursively as being either strings or
lists of ropes. Actually this is not entirely true. The value
returned must be a table, whose list-part is a rope. It can also
optionally have any of the following words as indices:
Variable names in Weave must be composed of letters, digits and underscores and may not start with a digit. White space and newlines are only significant as separators of words. Functions are applied to comma-separated lists of arguments in parentheses. In case of a single argument the parentheses may be omitted if the argument is a literal string or a literal list - that is if the next token is one of: ", ', [[, { . Inside quoted strings certain control characters can be expressed using the escape character \ . So the two strings:
Weave provides, beside the pseudotables TAG, MONOTAG, CLASS, the following built in functions:
Although !Weave was built with Lua, you do not need Lua installed
on your computer to use it. Similarly, the syntax of Weave
scripts follows (mostly) the rules of Lua syntax, but you do not
need to know Lua to write them. As explained in
BODYSTYLE
CHARSET
CSS
DOCTYPE
FILE
HEADER
LANG
QUIET
TITLE
BODYSTYLE
It is best to use CSS for defining the style for the
body
tag, but if you do want your HTML to include styles in
the tag itself, do this using the value assigned to BODYSTYLE.
=> { BODYSTYLE = [[width: 800px;]]; myrope; }
CHARSET
The default character set is utf-8. If you want another
to override this, assign its name to CHARSET.
CSS
This must optionally be assigned a value which is a rope whose
strings are the URLs of CSS files you want the document to use.
Each one will have its own declaration in the header of the
document.
=> { CSS = { "mystyle.css"; "yourstyle.css"; }; myrope; }
DOCTYPE
The default DOCTYPE tag, the first word of the document, is
<!DOCTYPE html>
. You can override this by assigning a rope to this. You had better know what you are
doing.
FILE
You can override the default output name by assigning
its filepath to this.
HEADER
You can use this to put more stuff into the document header by assigning
a rope to it.
LANG
The default value of the LANG attribute in the document header is
en
. You can override this by assigning a string (not a rope) language code to this.
QUIET
Assigning any non-nil value, apart from
false
, to this will suppress the confirmatory taskwindow message if compilation
is successful.
TITLE
This sets the value in the TITLE tag in the header. The default value
is
???
.
Variable names in Weave must be composed of letters, digits and underscores and may not start with a digit. White space and newlines are only significant as separators of words. Functions are applied to comma-separated lists of arguments in parentheses. In case of a single argument the parentheses may be omitted if the argument is a literal string or a literal list - that is if the next token is one of: ", ', [[, { . Inside quoted strings certain control characters can be expressed using the escape character \ . So the two strings:
"one\ntwo\nthree" [[ one two three]]are the same.
Weave provides, beside the pseudotables TAG, MONOTAG, CLASS, the following built in functions:
It is convenient to write pieces of Weave code that can be re-used in
many scripts in a separate file, to avoid rewriting. The function
require
takes as argument either the name of a file in !Weave.lib or
the absolute pathname of a file and returns the value given
by the file's final return statement. It is intelligent in
the sense that if a file has been loaded already, no loading is done
subsequently. Local variables used in such
code have scope only within the file. At present only three files
are provided in !Weave.lib:
Include List Table
Include defines a function INCLUDE that reads a file as a string.
List defines two functions: list and linkify. They can be used
like this:
local list, linkify in require "List" mylist = list { rope_1; .... ; rope_n } my_links = linkify { { addr_1; label_1; } .................... { addr_n; label_n; } }mylist and my_links will be unordered lists. The functions can take two further arguments, the first for the attributes of the ul tag, the second for the attributes of the li tag.
Table defines a function TABLE, used like this:
local TABLE in require "Table" mytable = TABLE { { a_11; a_12; ......... ; a_1n; }; ................................. { a_m1; a_m2; ......... ; a_mn; }; }which can take three more arguments for the attributes of the tags table, tr, td.
LINK
This uses the anchor tag to make links:
LINK "http:yoyodyne.org/news.html" "Try it now!";produces HTML
<a href="http:yoyodyne.org/news.html>Try it now!</a>
OBEY$DIR
This function takes as a string argument a relative address of a
file (relative to the output HTML file) and returns its absolute
address. This is useful with require.
my_db = require (OBEY$DIR [[dbase_file]])
REM
Puts an HTML comment into the document
TEXT
Text often needs cleaning up before being inserted into HTML.
Top-bit-set characters need to be replaced by character entities,
and so do angle-brackets and ampersands. This function, from
ropes to ropes does it for you. It will also evaluate expressions
that are enclosed in parentheses and prefixed by a $-sign.
If the expression contains variables, x, y, ... then TEXT
must be given a second argument { x = x; y = y; .... }
for the evaluation to take place.
STYLE
This function takes a string, puts doublequotes round it and
prefixes
style=
. Useful for inserting inline styles into tags.